<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@include file="/context/mytags.jsp" %>
<div class="col-md-12">
    <div class="panel-search">
        <form class="form-inline" action="/orders/list">
            <div class="form-group">
                <%--订单状态：1、等待确认，2、等待检查，3、等待分配，4、等待方案,5、已完成，6、已取消--%>
                <button type="button" id="statusIdZero" class="btn btn-info" onclick="selectStatus(0,this)">
                    <i class="fa"></i> 全部订单(<label id="orderAll"></label>)
                </button>
                <button type="button" id="statusIdOne" class="btn btn-info" onclick="selectStatus(1,this)">
                    <i class="fa"></i> 等待确认(<label id="orderConfirm"></label>)
                </button>
                <button type="button" id="statusIdThree" class="btn btn-info" onclick="selectStatus(2,this)">
                    <i class="fa"></i> 等待检查(<label id="orderCheck"></label>)
                </button>
                <button type="button" id="statusIdTwo" class="btn btn-info" onclick="selectStatus(3,this)">
                    <i class="fa"></i> 等待分配(<label id="orderAssign"></label>)
                </button>
                <button type="button" id="statusIdFour" class="btn btn-info" onclick="selectStatus(4,this)">
                    <i class="fa"></i> 等待方案(<label id="orderProgram"></label>)
                </button>
                <button type="button" id="statusIdFive" class="btn btn-info" onclick="selectStatus(5,this)">
                    <i class="fa"></i> 已完成(<label id="orderCompleted"></label>)
                </button>
                <button type="button" id="statusIdSix" class="btn btn-info" onclick="selectStatus(6,this)">
                    <i class="fa"></i> 已取消(<label id="orderCancel"></label>)
                </button>
                <input type="hidden" name="orderStatus" id="orderStatusId" value="0"/>
            </div>
            <br><br>
            <div class="form-group">
                <label for="orderCode" class="control-label">订单编号：</label>
                <input type="text" name="orderCode" class="form-control" onblur="allTrim(this);"/>
            </div>
            <div class="form-group">
                <label for="orderCode" class="control-label">姓名/手机号：</label>
                <input type="text" name="nameOrPhone" class="form-control" onblur="allTrim(this);"/>
            </div>
            <div class="form-group">
                <label for="orderCode" class="control-label">医生/医院名称：</label>
                <input type="text" name="doctorOrHospital" class="form-control" onblur="allTrim(this);"/>
            </div>
            <%--用于判断到底是后台管理还是国内医院或护士--%>
            <input type="hidden" name="pageType" value="<spring:message code="sys.pagyType"></spring:message>">
        </form>
        <div class="btn-div">
            <div class="div-left">
                <button type="button" class="btn btn-info" onclick="add('/orders/orders')">
                    <i class="fa fa-plus"></i> <spring:message code="btn.add"></spring:message>
                </button>
            </div>
            <div class="div-right">
                <button type="button" class="btn btn-info" onclick="search()">
                    <i class="fa fa-search"></i> <spring:message code="btn.search"></spring:message>
                </button>
                <button type="button" class="btn btn-info" onclick="reset()">
                    <i class="fa fa-repeat"></i> <spring:message code="btn.reset"></spring:message>
                </button>
            </div>
        </div>
    </div>
    <div class="panel-content"></div>
    <div class="panel-show"></div>
</div>
<script type="text/javascript" src="<c:url value="/static/custom/datepicker-util.js"></c:url>"></script>
<script type="text/javascript">
    $(function () {
        search();
        queryStatistics();
    });

    /**
     * 数据统计
     * @param status 状态
     * @param obj 点击的按钮
     */
    function selectStatus(status, obj) {
        var currentId = obj.id;
        $("#orderStatusId").val(status);
        $("button[id^='statusId']").removeClass("btn-success").addClass("btn-info");
        $("#" + currentId).removeClass("btn-info").addClass("btn-success");
        search();
        queryStatistics();
    }

    /**
     * 查询科室的统计信息
     */
    function queryStatistics() {
        $.ajax({
            type: 'post',
            url: '<c:url value="/orders/queryStatistics"></c:url>',
            data: null,
            dataType: 'json',
            success: function (data) {
                if (!checkResultCode(data.code)) {
                    alert(data.message);
                } else {
                    //全部订单
                    $("#orderAll").text(data.data.orderAll);
                    //等待确认
                    $("#orderConfirm").text(data.data.orderConfirm);
                    //等待分配
                    $("#orderAssign").text(data.data.orderAssign);
                    //等待检查
                    $("#orderCheck").text(data.data.orderCheck);
                    //等待方案
                    $("#orderProgram").text(data.data.orderProgram);
                    //已完成
                    $("#orderCompleted").text(data.data.orderCompleted);
                    //已取消
                    $("#orderCancel").text(data.data.orderCancel);
                }
            }
        });
    }
</script>